﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IForm_EditVisualTheme</summary>
    public class IForm_EditVisualTheme : IForm
    {
        public IVisualTheme Value; // Objekt na editaciu
        protected IGroupBox FGrp; // Controls
        protected IButton FBtn_Default, FBtn_OK, FBtn_Cancel;
        protected IComboBox FCombo_Groups;
        protected IListView FList;

        /// <summary>Konstruktor</summary>
        public IForm_EditVisualTheme()
        {
            Value = new IVisualTheme(); // Vytvorim objekt
        }
        /// <summary>Dispose metoda</summary>
        /// <param name="disposing">parameter</param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing); // Volam predchodcu
            Value = (IVisualTheme)ICore.DisposeObject(Value); // Zrusim objekt
        }

        /// <summary>Metoda OnCreateForm</summary>
        /// <returns>true / false</returns>
        protected override bool OnCreateForm()
        {
            if (!base.OnCreateForm()) return false; // Volam predchodcu

            FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; ShowInTaskbar = false; MinimizeBox = MaximizeBox = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; // Inicializacia vlastnosti

            Text = lang.FORM_EDIT_VISUAL_THEME_TEXT_4;
            SetBounds(0, 0, 700, 500); System.Drawing.Size CS = ClientSize;

            FGrp = new IGroupBox(); // Vytvorim groupbox
            FBtn_Default = new IButton(lang.FORM_EDIT_VISUAL_THEME_TEXT_1, Event_DefaultBtnClick);
            FBtn_OK = new IButton(lang.FORM_EDIT_VISUAL_THEME_TEXT_2);
            FBtn_Cancel = new IButton(lang.FORM_EDIT_VISUAL_THEME_TEXT_3);

            FCombo_Groups = new IComboBox(); // Vytvorim combobox
            for (int i = 0; i < IVisualTheme.VISUAL_STYLE_GROUP_ID_LAST; i++) if (IVisualTheme.GroupHasItems(i)) FCombo_Groups.AddItem(IVisualTheme.GroupID2Str(i), i);

            FList = new IListView(); FList.HideSelection = false; FList.FullRowSelect = true; FList.ShowItemToolTips = true; // Vytvorim listview
            FList.CreateColumns(new string[] { lang.FORM_EDIT_VISUAL_THEME_TEXT_5 }, new int[] { 650 }, new System.Windows.Forms.HorizontalAlignment[] { System.Windows.Forms.HorizontalAlignment.Left });

            FGrp.Controls.AddRange(new System.Windows.Forms.Control[] { FCombo_Groups, FList }); // Zaradim
            Controls.AddRange(new System.Windows.Forms.Control[] { FGrp, FBtn_Default, FBtn_OK, FBtn_Cancel }); // Zaradim

            IControl.PlaceControl_Inside(FGrp, this, 10, 10, 10, 50); // Umiestnim prvky do okna
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FBtn_Default, FGrp, 0, 10);
            IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_Cancel, FGrp, 0, 10);
            IControl.PlaceControl_Outside_TopRight_LeftTop(FBtn_OK, FBtn_Cancel, 0, 10);
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FCombo_Groups, FGrp, 4, 10); FCombo_Groups.Width = FGrp.ClientSize.Width - 8;
            FList.Width = FCombo_Groups.Width; IControl.PlaceControl_Outside_LeftTop_LeftBottom(FList, FCombo_Groups, 0, 4); FList.Height = FGrp.ClientSize.Height - FCombo_Groups.Bottom - 8;

            AcceptButton = FBtn_OK; CancelButton = FBtn_Cancel; FBtn_OK.Focus(); FBtn_OK.DialogResult = System.Windows.Forms.DialogResult.OK;

            // Nastavim eventy
            FCombo_Groups.SelectedIndexChanged += Event_SelectedIndexChanged;
            FList.ItemActivate += Event_ItemActivate;

            CreateList(FCombo_Groups.FirstID);
            return true; // Vsetko OK
        }
        /// <summary>Vytvorenie zoznamu podla zadanej skupiny</summary>
        /// <param name="pGroupID">ID skupiny</param>
        protected void CreateList(int pGroupID)
        {
            FCombo_Groups.SelectedIntID = pGroupID; // Nastavim skupinu v comboboxe

            FList.BeginCreate(); // Zacinam vytvarat obsah

            for (int i = 0; i < IVisualTheme.VISUAL_STYLE_ID_LAST; i++) // Prejdem vsetky funkcie
            {
                if (!IVisualTheme.CanEdit(i)) continue;
                if (IVisualTheme.ID2GroupID(i) != pGroupID) continue;
                FList.AddItem(IVisualTheme.SubgroupID2Str(IVisualTheme.ID2SubgroupID(i)), IVisualTheme.ID2Str(i), i);
            }

            FList.EndCreate(-1); // Koniec vytvarania
        }
        /// <summary>Zmena hodnoty uzivatelom</summary>
        /// <param name="pID">ID nastavenia</param>
        /// <returns>true / false</returns>
        protected bool EditValue(int pID)
        {
            switch (pID)
            {
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_UP_STATUS_ACTIVE: return Value.FileExplorer_UpStatus_Active.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_UP_STATUS_INACTIVE: return Value.FileExplorer_UpStatus_InActive.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_DOWN_STATUS_ACTIVE: return Value.FileExplorer_DownStatus_Active.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_DOWN_STATUS_INACTIVE: return Value.FileExplorer_DownStatus_InActive.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_DEFAULT: return Value.FileExplorer_List_DefaultItem.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_DIRECTORY: return Value.FileExplorer_List_Directory.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_FILE: return Value.FileExplorer_List_File.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_ARCHIVE_ITEM: return Value.FileExplorer_List_ArchiveItem.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_COMPRESSED_ITEM: return Value.FileExplorer_List_CompressedItem.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_ENCRYPTED_ITEM: return Value.FileExplorer_List_EncryptedItem.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_HIDDEN_ITEM: return Value.FileExplorer_List_HiddenItem.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_READONLY_ITEM: return Value.FileExplorer_List_ReadOnlyItem.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_SYSTEM_ITEM: return Value.FileExplorer_List_SystemItem.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_SELECTED_ITEM: return Value.FileExplorer_List_SelectedItem.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, false);
                case IVisualTheme.VISUAL_STYLE_ID_FILE_EXPLORER_LIST_CURSOR: return Value.FileExplorer_List_Cursor.EditWithForm(lang.FORM_EDIT_VISUAL_THEME_TEXT_7, true, true, true, true);
                default: return false;
            }
        }

        /// <summary>Event: SelectedIndexChanged</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_SelectedIndexChanged(object pSender, EventArgs e)
        {
            CreateList(FCombo_Groups.SelectedIntID); // Volam zmenu skupiny
        }
        /// <summary>Event: ItemActivate</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_ItemActivate(object pSender, EventArgs e)
        {
            int ID = FList.SelectedIntTag; // Ziskam ID funkcie
            if (ID == -1) return; // Ziadna?
            EditValue(ID);
        }
        /// <summary>Event: Click pre tlacidlo 'Prednastavene'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_DefaultBtnClick(object pSender, EventArgs e)
        {
            if (IApp.ShowQuestion(lang.FORM_EDIT_VISUAL_THEME_TEXT_6)) // Potvrdim
            {
                Value.LoadTheme(0); // Nacitam prednastavene
            }
        }
    }
}
